package cn.edu.zafu.bigdata.Yum;

import java.util.List;
public class GenericMaxFinder {
    public static <T extends Comparable<T>> T findMax(List<T> list){
        if(list==null||list.isEmpty()){
            System.out.println("List must not be null or empty!");
        }
        T max=list.get(0);
        for(T item:list){
            if(item.compareTo(max)>0){
                max=item;
            }
        }
        return max;
    }
    public static void main(String[] args) {
        List<Integer> intlist = List.of(1,2,3,4,5,6,9,8,7);
        List<String> strlist = List.of("hu","yan","fang","ze","chen","qi");
        Integer Intmax = findMax(intlist);
        String Strmax = findMax(strlist);
        System.out.println("利用泛型findmax找到的最大数字是"+Intmax);
        System.out.println("利用泛型findmax找到的最大字符串是"+Strmax);
    }
}
